
export function qrcodeCanvas (width,height,shareImg,qrcodeImg,brandLogo = null) {
    const canvas = document.createElement('canvas')
    const cvs = canvas.getContext('2d')
    canvas.width = width
    canvas.height = height
    cvs.drawImage(shareImg, 0, 0, parseInt(width), parseInt(height));
    var imgData=cvs.getImageData(0,0,width,height)
    let num = 0
    let leftIndex = 0
    let rightIndex = 0
    for (var i=0;i<imgData.data.length;i+=4){
        if(imgData.data[i+3] === 0 && num == 0){
            leftIndex = i
            num++
        }
        if(imgData.data[i+3] !== 0 && num === 1){
            num++
            rightIndex = i
        }
    }
    const dp = imgData.data.length / width / height
    const y = (Math.floor(leftIndex / width /dp) )
    const x = (leftIndex - ( y * dp * width)) / dp + 4
    const qrWidth = (rightIndex - leftIndex) / dp - 8
    cvs.drawImage(qrcodeImg,x,y+4,qrWidth,qrWidth)
    if(brandLogo){
        const logox = x + qrWidth/2 - 22.5
        const logoy = y + qrWidth/2 - 22.5
        cvs.drawImage(brandLogo,logox,logoy,45,45)
    }
    const url = canvas.toDataURL('image/png',2);
    return url
}